<template>
  <div class="browseHistory">
    <header>
      <div class="back">
        <van-icon name="arrow-left" size="22" color="black" @click="back" />
      </div>
      <div class="title">播放历史</div>
      <div></div>
    </header>
    <div class="index" v-if="browseHistorys.length > 0">
      <BrowseHistoryItem
        v-for="item in browseHistorys"
        :key="item"
        :videoId="item"
      />
    </div>
    <div class="none" v-else>还没有历史记录</div>
  </div>
</template>

<script>
import BrowseHistoryItem from "@/components/BrowseHistoryItem.vue";

export default {
  name: "BrowseHistory",
  components: {
    BrowseHistoryItem,
  },
  data() {
    return {
      browseHistorys: [],
    };
  },
  mounted() {
    this.browseHistorys = JSON.parse(
      localStorage.getItem("nsBrowseHistory") || "[]"
    );
  },
  methods: {
    back() {
      window.history.go(-1);
    },
  },
};
</script>

<style lang="scss" scoped>
.browseHistory {
  padding: 50px 15px 0px;

  header {
    background-color: white;
    border-bottom: 1px solid #f2f2f2;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10;
    height: 50px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;

    > div {
      width: 33%;
    }

    .back {
      i {
        margin-left: 15px;
      }
    }

    .title {
      font-size: 20px;
      font-weight: bold;
      text-align: center;
    }
  }

  .none {
    color: #999;
    text-align: center;
    margin-top: 50px;
  }
}
</style>
